package 池塘计数;

import java.util.*;

public class Main {
    static int N = 1010, n, m;
    static char[][] g = new char[N][N];
    static boolean[][] st = new boolean[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        for (int i = 0; i < n; i++) {
            g[i] = in.next().toCharArray();
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == 'W' && !st[i][j]) {
                    cnt++;
                    bfs(new PII(i, j));
                }
            }
        }
        System.out.println(cnt);
    }

    private static void bfs(PII start) {
        Queue<PII> q = new LinkedList<>();
        q.offer(start);
        st[start.x][start.y] = true;
        while (!q.isEmpty()) {
            PII t = q.poll();
            for (int i = t.x - 1; i <= t.x + 1; i++) {
                for (int j = t.y - 1; j <= t.y + 1; j++) {
                    if (i == t.x && j == t.y) {
                        continue;
                    }
                    if (i < 0 || i >= n || j < 0 || j >= m) {
                        continue;
                    }
                    if (st[i][j]) {
                        continue;
                    }
                    if (g[i][j] != 'W') {
                        continue;
                    }
                    q.offer(new PII(i, j));
                    st[i][j] = true;
                }
            }
        }
    }
}

class PII {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }
}